/**
 * Created by yhg97p on 2016/9/27.
 */
define(['app', 'filters/filters'],function(app){
    app.register.controller('compProfession', function($scope, $http, $state, $sce,$stateParams,$rootScope, $confirm,$cookieStore){
        $scope.loading_show = true;
        $scope.tip = 0;
        $scope.tipShowzy = false;
        $scope.click_zy = 1;//进来点击专业不会请求接口
        $scope.load = {
            _getMajorinfo: function(){  //专业类别和专业
                $http({
                    url: app._baseUrl + 'Qy/Category/index',
                    method: 'GET',
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                }).success(function(res){
                	if(res.success){
                        $scope.loading_show = false;
                		$scope.Majorinfo = res.data;
                	}else{
                		if(res.code==-102){
                            history.back();
                            $rootScope.num=0;
                		}
                	}
                });
            },
            init: function(){
                $scope.Majorinfo = [];
                $scope.Compinfo = [];
                this._getMajorinfo && this._getMajorinfo();
                this._getCompinfo && this._getCompinfo();
            }
        };
        $scope.load.init && $scope.load.init();
        $scope.goCompCourse = function(category, major,cate_id,parIndex){
          if(major.lock_status){//如果锁状态是1，即开锁，即隐藏i标签
              //判断是否要能力测评
              if($scope.Majorinfo[parIndex].is_ability_check==0){//未测评
                  $scope.nengli=1;
                  $rootScope.cate_id_nengli = cate_id;
                  $cookieStore.put("cate_id",$rootScope.cate_id_nengli);
              }else{//已测评过
                  var url = $state.href('app.compCourse',{cate_id:category.cate_id,specialty_id:major.specialty_id});
                  // window.open(url,'_blank');
                  window.location.href = url;
              }
          }else{//未开锁
            if(cate_id==$scope.app.user.data.post_id||$scope.app.user.data.role_id==1||$scope.app.user.data.role_id==2){//岗位是对应到的或者是老板
                  //后期加弹窗加这里
                $scope.sec = 5;
                var interval = setInterval(function() {//设置定时器
                    if($scope.sec > 0) {
                        $scope.sec--;
                        $scope.tipShowzy = true;//提示显示
                        $('.tool_zy').fadeIn(600);
                    } else {
                        clearInterval(interval);
                        $scope.tipShowzy = true;
                        $('.tool_zy').fadeOut(600);
                    }
                    $scope.$digest();//脏数据检验
                }, 500)

            }else{
                $scope.tipPop();
            }
          }
        };

        //温馨提示
        $scope.tipPop = function() {
            $scope.tipModal.show();
          };
       // 编辑课程
       $scope.tipModal = {
        isShow: false,
        title: '温馨提示',
        data: {},
        confirm: function() {
          this.hide()
        },
        cancel: function() {
          this.hide()
        },
        hide: function() {
          this.isShow = false;
        },
        show: function() {
          this.isShow = true;
        }
      }
       //能力测评
        $scope.nengli = 0;
        $scope.state_go = function(){
            $cookieStore.put('nl_tc',1);
            $state.go('app.nenglitest')
        }
        $scope.nl_clo = function(){
            $scope.nengli = 0;
        }
        //下载资料
        $scope.download_video = function(file_url){
            // console.log(file_url)
            window.location.href = encodeURI(file_url);
            // window.open(file_url,'_blank')
        }
    })
});